const momentService = require('../service/moment.service')
class MomentController {
  async create(ctx, next) {
    // 1. 获取数据 (user_id,content,)
    const userId = ctx.user.id
    const content = ctx.request.body.content
    // console.log(userId, content);
    const result = await momentService.create(userId, content)
    ctx.body = result
  }
  async detail(ctx, next) {
    // 拿到 momentid
    const momentId = ctx.params.momentId
    console.log(momentId);
    const result = await momentService.getMonentById(momentId)
    ctx.body = result
  }
  async list(ctx, next) {
    console.log('执行~~~~');
    const { offset, size } = ctx.query
    console.log('size   ' + size + '  offset ' + offset);
    const result = await momentService.getMonentList(size, offset)
    ctx.body = result
  }
  async update(ctx, next) {
    const { momentId } = ctx.params
    const { content } = ctx.request.body
    const { id } = ctx.user
    console.log('修改内容的时候', momentId, content);
    const result = await momentService.update(content, momentId)
    ctx.body = result

  }
  async remove(ctx, next) {
    const { momentId } = ctx.params
    const result = await momentService.remove(momentId)
    ctx.body = result

  }
}

module.exports = new MomentController()